<html>
<head><meta charset="utf-8"><title>PhantomConst · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html">PhantomConst</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="167234324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167234324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167234324">(Jun 03 2019 at 21:36)</a>:</h4>
<p>Will there be a <code>PhantomData</code> equivalent for const generics?</p>



<a name="167234918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167234918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167234918">(Jun 03 2019 at 21:45)</a>:</h4>
<p>The current plan is that it won't be required</p>



<a name="167234944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167234944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167234944">(Jun 03 2019 at 21:45)</a>:</h4>
<p>since there's no variance etc. to deal with</p>



<a name="167284683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167284683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167284683">(Jun 04 2019 at 11:57)</a>:</h4>
<p>I wanted to make a </p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">FakeArray</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>
</pre></div>


<p>What would be the way to do so?</p>



<a name="167285162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167285162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> yodal <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167285162">(Jun 04 2019 at 12:02)</a>:</h4>
<p>That there should work</p>



<a name="167285251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167285251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167285251">(Jun 04 2019 at 12:03)</a>:</h4>
<p>hm; did I not even try it?</p>



<a name="167285316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167285316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167285316">(Jun 04 2019 at 12:03)</a>:</h4>
<p><span aria-label="face palm" class="emoji emoji-1f926" role="img" title="face palm">:face_palm:</span></p>



<a name="167285360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167285360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167285360">(Jun 04 2019 at 12:04)</a>:</h4>
<p>Thank you <span class="user-mention" data-user-id="218608">@yodal</span></p>



<a name="167285387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167285387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167285387">(Jun 04 2019 at 12:04)</a>:</h4>
<p>I'm just so used to needing to make use of the parameters</p>



<a name="167285672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167285672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167285672">(Jun 04 2019 at 12:09)</a>:</h4>
<p><span class="user-mention" data-user-id="218608">@yodal</span> should I file this?</p>
<div class="codehilite"><pre><span></span><span class="cp">#![feature(const_generics)]</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">FakeArray</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">FakeArray</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="p">}</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">len</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">N</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">fa</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">FakeArray</span>::<span class="o">&lt;</span><span class="p">{</span><span class="w"> </span><span class="mi">32</span><span class="w"> </span><span class="p">}</span><span class="o">&gt;</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">fa</span><span class="p">.</span><span class="n">len</span><span class="p">());</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span>error: internal compiler error: src/librustc/infer/canonical/canonicalizer.rs:553: failed to lift `QueryResponse { var_values: CanonicalVarValues { var_values: [^0, Const { ty: _, val: Infer(Canonical(DebruijnIndex(0), 1)) }] }, region_constraints: [], certainty: Proven, value: FakeArray&lt;^0, _: _&gt; }`, canonicalized from `QueryResponse { var_values: CanonicalVarValues { var_values: [{integer}, Const { ty: _, val: Infer(Var(_#0c)) }] }, region_constraints: [], certainty: Proven, value: FakeArray&lt;{integer}, _: _&gt; }`

thread &#39;rustc&#39; panicked at &#39;Box&lt;Any&gt;&#39;, src/librustc_errors/lib.rs:637:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error
</pre></div>


<p>I found <a href="https://github.com/rust-lang/rust/issues/60879" target="_blank" title="https://github.com/rust-lang/rust/issues/60879">https://github.com/rust-lang/rust/issues/60879</a> but it's been closed and this still repros</p>



<a name="167286190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167286190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> yodal <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167286190">(Jun 04 2019 at 12:16)</a>:</h4>
<p>Interesting, I tested that one myself and <span class="user-mention" data-user-id="121053">@varkor</span> added a regression test so it shouldn't repro on the latest</p>



<a name="167286584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167286584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> yodal <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167286584">(Jun 04 2019 at 12:22)</a>:</h4>
<p>Could you submit an issue? Yours creates an error while the code in that issue doesn't.</p>



<a name="167286594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167286594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167286594">(Jun 04 2019 at 12:22)</a>:</h4>
<p>Sure can!</p>



<a name="167286606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167286606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> yodal <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167286606">(Jun 04 2019 at 12:22)</a>:</h4>
<p>At any rate, if not for that ICE, that code should work just fine</p>



<a name="167286892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/PhantomConst/near/167286892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> yodal <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/PhantomConst.html#167286892">(Jun 04 2019 at 12:27)</a>:</h4>
<p>Ah, I see what is triggering it. Your code has an explicit const param in the initializer while there code infers it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>